﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise.data {
    import flash.utils.*;
    import Classes.util.*;
    import __AS3__.vec.*;
    import Modules.franchise.display.*;
    import Classes.orders.*;

    public class OwnedFranchiseData {

        private var m_franchiseType:String;
        private var m_franchiseName:String;
        private var m_pendingName:String;
        private var m_locations:Dictionary;
        private var m_franchiseSaleCommType:String;
        private var m_franchiseSaleCommCost:int;
        private var m_dailyBonusAvailable:Boolean = true;
        private var m_dailyBonusValue:int = 0;
        private var m_dailyBonusLastCollect:int;

        public function OwnedFranchiseData(_arg1:String, _arg2:String, _arg3:String, _arg4:Dictionary, _arg5:int){
            var _local6:int;
            var _local7:int;
            super();
            this.m_franchiseType = _arg1;
            this.m_franchiseName = _arg2;
            this.m_pendingName = _arg3;
            this.m_locations = _arg4;
            if (((!((this.m_franchiseType == "history"))) && (!((this.m_franchiseType == "bus_dummy"))))){
                this.m_franchiseSaleCommType = Global.gameSettings.getItemByName(this.m_franchiseType).commodityName;
                this.m_franchiseSaleCommCost = (Global.gameSettings.getItemByName(this.m_franchiseType).commodityReq / 2);
            };
            if (((_arg5) && (_arg4))){
                this.m_dailyBonusLastCollect = Math.floor(_arg5);
                _local6 = (GlobalEngine.getTimer() / 1000);
                _local7 = FranchiseMenu.dailyCycleDelta;
                if ((_local6 - this.m_dailyBonusLastCollect) < _local7){
                    this.m_dailyBonusAvailable = false;
                };
            };
            this.m_dailyBonusValue = this.getLocationCount();
        }
        public static function loadObject(_arg1:Object):OwnedFranchiseData{
            var _local3:String;
            var _local4:String;
            var _local5:String;
            var _local6:Object;
            var _local7:Number;
            var _local8:Dictionary;
            var _local9:String;
            var _local10:String;
            var _local11:Object;
            var _local2:OwnedFranchiseData;
            if (_arg1){
                _local3 = _arg1["name"];
                _local4 = _arg1["franchise_name"];
                _local5 = _arg1["pendingName"];
                _local6 = _arg1["locations"];
                _local7 = _arg1["time_last_collected"];
                _local8 = new Dictionary();
                for (_local9 in _local6) {
                    _local10 = GameUtil.formatServerUid(_local9);
                    if (_local9 == "i-1"){
                        _local10 = "-1";
                    };
                    _local11 = _local6[_local9];
                    _local8[_local10] = FranchiseExpansionData.loadObjectWithTypeAndLocation(_local3, _local10, _local11);
                };
                _local2 = new OwnedFranchiseData(_local3, _local4, _local5, _local8, _local7);
            };
            return (_local2);
        }
        public static function loadPendingObject(_arg1:Vector.<LotOrder>):OwnedFranchiseData{
            var _local3:LotOrder;
            var _local4:String;
            var _local5:String;
            var _local6:String;
            var _local7:Dictionary;
            var _local8:LotOrder;
            var _local9:String;
            var _local2:OwnedFranchiseData;
            if (((_arg1) && (_arg1.length))){
                _local3 = (_arg1[0] as LotOrder);
                _local4 = _local3.getResourceType();
                _local5 = _local3.getOrderResourceName();
                _local6 = null;
                _local7 = new Dictionary();
                for each (_local8 in _arg1) {
                    _local9 = _local8.getRecipientID();
                    _local7[_local9] = FranchiseExpansionData.loadPendingObject(_local8);
                };
                _local2 = new OwnedFranchiseData(_local4, _local5, _local6, _local7, 0);
            };
            return (_local2);
        }
        public static function loadCitySamObject(_arg1:String):OwnedFranchiseData{
            var _local2 = (_arg1 + "_citySamName");
            var _local3:String = ZLoc.t("Items", _local2);
            var _local4:Dictionary = new Dictionary();
            var _local5:int = _arg1.length;
            var _local6:String;
            var _local7:int;
            while (_local7 < _local5) {
                _local4[_local7.toString()] = FranchiseExpansionData.loadCitySamObject(_arg1, _local7);
                _local7++;
            };
            return (new OwnedFranchiseData(_arg1, _local3, _local6, _local4, 0));
        }

        public function get franchiseType():String{
            return (this.m_franchiseType);
        }
        public function get franchiseName():String{
            return (this.m_franchiseName);
        }
        public function get pendingName():String{
            return (this.m_pendingName);
        }
        public function get locations():Dictionary{
            return (this.m_locations);
        }
        public function get saleCost():int{
            return (this.m_franchiseSaleCommCost);
        }
        public function get commType():String{
            return (this.m_franchiseSaleCommType);
        }
        public function get dailyBonusAvailable():Boolean{
            return (this.m_dailyBonusAvailable);
        }
        public function get dailyBonusValue():int{
            return (this.m_dailyBonusValue);
        }
        public function get dailyBonusLastCollect():int{
            return (this.m_dailyBonusLastCollect);
        }
        public function set franchiseName(_arg1:String):void{
            this.m_franchiseName = _arg1;
        }
        public function set pendingName(_arg1:String):void{
            this.m_pendingName = _arg1;
        }
        public function set dailyBonusAvailable(_arg1:Boolean):void{
            this.m_dailyBonusAvailable = _arg1;
        }
        public function set dailyBonusLastCollect(_arg1:int):void{
            this.m_dailyBonusLastCollect = _arg1;
        }
        public function getLocationCount():Number{
            var _local2:FranchiseExpansionData;
            var _local1:Number = 0;
            for each (_local2 in this.locations) {
                _local1++;
            };
            return (_local1);
        }
        public function clone():OwnedFranchiseData{
            return (new OwnedFranchiseData(this.m_franchiseType, this.m_franchiseName, this.m_pendingName, this.cloneLocations(), this.m_dailyBonusLastCollect));
        }
        public function merge(_arg1:OwnedFranchiseData):void{
            var _local2:FranchiseExpansionData;
            if (((_arg1) && ((_arg1.franchiseType == this.franchiseType)))){
                for each (_local2 in _arg1.locations) {
                    if (!this.hasLocation(_local2.locationUid)){
                        this.addLocation(_local2);
                    };
                };
            };
        }
        private function cloneLocations():Dictionary{
            var _local2:Object;
            var _local3:Object;
            var _local1:Dictionary = new Dictionary();
            for (_local2 in this.m_locations) {
                _local3 = this.m_locations[_local2];
                _local1[_local2] = _local3;
            };
            return (_local1);
        }
        public function hasLocation(_arg1:String):Boolean{
            return (((this.locations) && (!((this.locations[_arg1] == null)))));
        }
        public function addLocation(_arg1:FranchiseExpansionData):void{
            this.locations[_arg1.locationUid] = _arg1;
        }

    }
}//package Modules.franchise.data 
